<template>
  <div class="m--list-tabs__item">
    <el-tabs>
      <el-tab-pane v-for="(item, index) in list" :key="index" :label="item.title">
        <el-scrollbar max-height="300px">
          <div
            class="container"
            @click="clickItem(listItem, listIndex)"
            v-for="(listItem, listIndex) in item.content"
            :key="listIndex"
          >
            <div class="avatar" v-if="listItem.avatar">
              <el-avatar :size="40" :src="listItem.avatar" />
            </div>
            <div class="content">
              <div class="title" v-if="listItem.title">
                <div>{{ listItem.title }}</div>
                <el-tag v-if="listItem.tagType" size="small" :type="listItem.tagType">{{
                  listItem.tag
                }}</el-tag>
              </div>
              <div class="time" v-if="listItem.desc">{{ listItem.desc }}</div>
              <div class="time" v-if="listItem.time">{{ listItem.time }}</div>
            </div>
          </div>
          <div class="actions">
            <div
              class="a-item"
              :class="{ border: actionIndex !== actions.length }"
              v-for="(action, actionIndex) in actions"
              :key="actionIndex"
              @click="clickAction(action, actionIndex)"
            >
              <div class="a-icon" v-if="action.icon">
                <component :is="`el-icon-${toLine(action.icon)}`"></component>
              </div>
              <div class="a-text">{{ action.text }}</div>
            </div>
          </div>
        </el-scrollbar>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script lang="ts" setup>
  import { PropType } from 'vue'
  import { ActionOptions, ListOptions, ListItem } from './types'
  import { toLine } from '../../../utils/index'

  let props = defineProps({
    // 列表的内容
    list: {
      type: Array as PropType<ListOptions[]>,
      required: true
    },
    // 操作的内容
    actions: {
      type: Array as PropType<ActionOptions[]>,
      default: () => []
    }
  })
  let emits = defineEmits(['clickItem', 'clickAction'])
  let clickItem = (item: ListItem, index: number) => {
    emits('clickItem', { item, index })
  }

  let clickAction = (item: ActionOptions, index: number) => {
    emits('clickAction', { item, index })
  }
</script>
<style lang="scss" scoped>
  .container {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    &:hover {
      background: #e6f6ff;
    }
    .avatar {
      flex: 1;
    }
    .content {
      flex: 3;
      .title {
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      .time {
        font-size: 12px;
        color: #999;
        margin-top: 4px;
      }
    }
  }
  .actions {
    height: 50px;
    display: flex;
    align-content: center;
    border-top: 1px solid #eee;
    .a-item {
      height: 50px;
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      .a-icon {
        margin-right: 4px;
        position: relative;
        top: 2px;
      }
    }
  }
  .border {
    border-right: 1px solid #eee;
  }
</style>
